package Basic;
/*
 * Description:
 * Author: AMark
 * Date:11/6/2023
 * Time:11:08 AM
 */

import java.sql.*;

public class Quire {
    static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
    static final String URL ="jdbc:mysql://localhost:3306/hw?serverTimezone = UTC";
    static final String USER = "root";
    static final String PASSWORD = "zhc20040309";
    public static void main(String[] args) {
        try {
            Class.forName(JDBC_DRIVER);
            //删除表
            String drop = "DROP TABLE temp";
            //增加
            String add = "INSERT INTO students VALUES('小美',10,100,'女')";
            //删除
            String delete = "DELETE FROM students WHERE name = '小美'";
            //修改数据
            String update = "UPDATE students SET score = 0 WHERE name = '小美'";
            //查询
            String query = "SELECT * FROM students";
            Connection con = DriverManager.getConnection(URL, USER, PASSWORD);
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(query);
            stmt.execute(add);
            while (rs.next()) {
                String id = rs.getString("sid");
                String name = rs.getString(2);
                System.out.println("学号：" + id + "姓名：" + name);
            }
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
